package com.leigang.monitor.controller;

import com.leigang.common.parent.pojo.dto.ServerMonitorDto;
import com.leigang.common.parent.pojo.vo.ResponseVo;
import com.leigang.monitor.entity.ServerMonitor;
import com.leigang.monitor.service.IServerMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author leig-a
 * @version 1.0
 * @desc
 * @date 2023/2/15 14:31
 */
@RestController
@RequestMapping("/server-monitor")
public class ServerMonitorController {
    private final IServerMonitorService serverMonitorService;
    public ServerMonitorController(IServerMonitorService serverMonitorService) {
        this.serverMonitorService = serverMonitorService;
    }

    @GetMapping
    public String hello(){
        return "monitor";
    }

    @GetMapping("/list")
    public ResponseVo<List<ServerMonitor>> list(){
        List<ServerMonitor> serverMonitors = serverMonitorService.listServerMonitor();
        return new ResponseVo<>(serverMonitors);
    }

    @PostMapping("/add")
    public ResponseVo<Boolean> add(@RequestBody ServerMonitorDto serverMonitorDto){
        boolean monitor = serverMonitorService.insertServerMonitor(serverMonitorDto);
        return new ResponseVo<>(monitor);
    }
}
